import BaseWindow from "../common-components/BaseWindow";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu('wnds/DailyRewardWnd')
export default class DailyRewardWnd extends BaseWindow {

    @property(cc.Label)
    countLbl: cc.Label = null;

    @property(cc.Node)
    heartNode: cc.Node = null;

    originPos: cc.Vec3 = null;

    requested = false;

    protected onLoad(): void {
        this.originPos = cc.v3(this.heartNode.getPosition());
    }

    initUI(hearts: number) {
        this.countLbl.string = `${hearts}`;
    }

    doClaimDailyReward(targetPosInWorld: cc.Vec2, cb?: () => void) {
        const pos = this.heartNode.parent.convertToNodeSpaceAR(targetPosInWorld);

        cc.tween(this.heartNode)
            .set({ active: true, position: this.originPos })
            .to(.4, { position: cc.v3(pos) }, { easing: 'sineIn' })
            .set({ active: false })
            .call(() => {
                cb && cb();
            })
            .start();
    }
}
